<?php


/**
 * Notes:
 * PROJECT_NAME : ERP v1.8 重构erp
 * User: 夏鱼儿<397072174@qq.com>
 * Date: 2024/3/26
 * Time: 16:16
 */

namespace app\tms\controller;



use app\service\base\Controller;
use app\tms\model\DeliverDriver;
use app\tms\model\DeliverCar;
use Exception;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;


class Base extends Controller
{

    public function initialize()
    {
        parent::initialize();
        $user_id     = request()->user_id;
        $this->appid = request()->header('appid', '');
        if ($user_id) {
            $this->user_id    = $user_id;
            $this->userInfo   = DeliverDriver::where('id', $user_id)->find();
            $this->company_id = $this->userInfo->company_id;
        }
    }


    /**
     * 获取当前车牌号
     * @param $driver_id
     * @return string
     */
    public function getCarNo($driver_id): string
    {
        return redis()->get('tms:driver:car' . $driver_id);
    }

    /**
     * @param $driver_id
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     * @throws Exception
     */
    public function getCarInfo($driver_id): array
    {
        $info = [];
        if($car_no = redis()->get('tms:driver:car' . $driver_id)){
            if(!$info = DeliverCar::where('no', $car_no)->find()){
                exception('车辆不存在');
            }
            $info = $info->toArray();
        }
        return $info;
    }


}